﻿using System;
using Guru.Web.UI;
using System.Data;
using Guru.Data;

public partial class UserControl_CustomerView : GuruUserControl
{
    protected override void OnInit(EventArgs e)
    {
        if (!IsPostBack)
        {
            this.uxGender.BindComboBox(HSMConstants.RefType.Gender);
            this.uxCustomerType.BindComboBox(HSMConstants.RefType.GuestType);
        }
    }   
    public void LoadByGuestID(string guestID)
    {
        GuruParameterCollection parameters = new GuruParameterCollection();
        parameters.AddUserLoggedParams();
        parameters.Add("@GuestID", guestID, DbType.Int32);
        DataTable tbGuest = HSMCommon.HSMBusiness.GetDataTable("spa_HSM_Guest_GetByID", parameters);

        this.ShowGuestInfor(tbGuest);
    }
    public void LoadByGuestByInvoice(int invoiceID)
    {
        GuruParameterCollection parameters = new GuruParameterCollection();
        parameters.AddUserLoggedParams();
        parameters.Add("@InvoiceID", invoiceID, DbType.Int32);
        DataTable tbGuest = HSMCommon.HSMBusiness.GetDataTable("spa_HSM_Guest_GetByInvoice", parameters);

        this.ShowGuestInfor(tbGuest);
    }
    protected void ShowGuestInfor(DataTable tbGuest)
    {
        this.uxCustomerName.Text = tbGuest.Rows[0]["GuestName"].ToSafeString();
        this.uxPhone.Text = tbGuest.Rows[0]["Phone"].ToSafeString();
        this.uxSocialID.Text = tbGuest.Rows[0]["IDNumber"].ToSafeString();
        this.uxGender.SetComboValue(tbGuest.Rows[0]["Gender"]);
        this.uxAddress.Text = tbGuest.Rows[0]["Address"].ToSafeString();
        this.uxEmail.Text = tbGuest.Rows[0]["Email"].ToSafeString();
        this.uxNationality.Text = tbGuest.Rows[0]["Nationality"].ToSafeString();
        this.uxPassport.Text = tbGuest.Rows[0]["VisaNumber"].ToSafeString();
        this.uxCustomerType.SetComboValue(tbGuest.Rows[0]["GuestType"]);
        this.uxPassportEndDate.SetDatePickerValue(tbGuest.Rows[0]["VisaExpiredDate"]);
    }
}
